#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
using namespace std;

int n, a[20], sz, dp[20][3][10];

int f(int i, int l, int s)
{
	if (i == sz)
	{
		if (l == 2) return 0;
		return s;
	}
	if (dp[i][l][s] != -1) return dp[i][l][s];
	dp[i][l][s] = 0;
	dp[i][l][s] += s;
	int j = 0, nless, nsum;
	if (i == 0) j = 1;
	for (; j < 10; j++)
	{
		nless = l;
		nsum = s;
		if (l == 0 && j < a[i]) nless = 1;
		if (l == 0 && j > a[i]) nless = 2;
		if (j % 2 == 0)
			nsum += j * 2;
		else nsum += j;
		nsum %= 10;
		dp[i][l][s] += f(i + 1, nless, nsum);
	}
	return dp[i][l][s];
}

int count(int n)
{
	if (n <= 0) return 0;
	sz = 0;
	while (n)
	{
		a[sz ++] = n % 10;
		n /= 10;
	}
	reverse(a, a + sz);
	memset(dp, -1, sizeof dp);
	return f(0, 0, 0);
}

int main()
{
	int T, a, b;
	cin >> T;
	for (int i = 0; i < T; i++)
	{
		scanf("%d%d", &a, &b);
		printf("%d\n", count(b) - count(a - 1));
	}
	return 0;
}

